package com.example.art.chapter3.one.one_four

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.GestureDetector
import android.view.MotionEvent
import com.example.art.R

/**
 * Created by 舍长
 * describe:手势操作测试Activity
 */
class GestureActivity : AppCompatActivity() {

    private var mgListener = MyGestureListener()
    private var mDetector: GestureDetector? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_gesture)
        mgListener = MyGestureListener()
        mDetector = GestureDetector(this, mgListener)
    }

    override fun onTouchEvent(event: MotionEvent): Boolean {
        return mDetector!!.onTouchEvent(event)
    }
}
/**
 * Created by 舍长 on 2019/4/8
 * describe:
 */
class MyGestureListener : GestureDetector.OnGestureListener {

    //按下
    override fun onDown(e: MotionEvent?): Boolean {
        Log.d("hello", "按下")
        return false
    }

    //按下一段时间，但是还没到长按
    override fun onShowPress(e: MotionEvent?) {
        Log.d("hello", "但是还没到长按")
    }

    //长按
    override fun onLongPress(e: MotionEvent?) {
        Log.d("hello", "长按")
    }

    //手指离开屏幕的一瞬间
    override fun onSingleTapUp(e: MotionEvent?): Boolean {
        Log.d("hello", "手指离开屏幕的一瞬间")
        return false
    }

    //在触摸屏上滑动
    override fun onScroll(e1: MotionEvent?, e2: MotionEvent?, distanceX: Float, distanceY: Float): Boolean {
        Log.d("hello", "在触摸屏上滑动")
        return false
    }

    //迅速滑动，并松开
    override fun onFling(e1: MotionEvent?, e2: MotionEvent?, velocityX: Float, velocityY: Float): Boolean {
        Log.d("hello", "迅速滑动，并松开")
        return false
    }


}